package com.ruoyi.web.controller.example;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.student.domain.Student;
import com.ruoyi.teacher.domain.Teacher;
import com.ruoyi.teacher.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "教师管理")
@RestController
@Anonymous

public class TeacherController {
    @Autowired
    TeacherService service;
    @Autowired
    RedisCache cache;
    @ApiOperation(value = "获取教师列表")
    @GetMapping("GetTeacherList")
    public AjaxResult GetTeacherAll(){
        List<Teacher> result = service.getTeacherList();
        return AjaxResult.success(result);
    }

    //尝试储存一个个简单的rediskey
    @ApiOperation(value = "教师测试redis")
    @GetMapping("SetTeacherKey")
    public AjaxResult SetTeacherKey(String name){
        //开始使用redis
        //setCacheObject 用户往redis存储一个key value 结构
        //后续我们可以根据储存的key，查询对应value
        //例如，我们的key 是2020510，value是传入的name，比如zhangsan
        //那我们查20240510的时候，就会返回zhangsan
        //例如mysql中的，select name from user where id = 20240510
        cache.setCacheObject("20240510",name);
        return AjaxResult.success();
    }
}
